import time

import requests, json, os
import yaml
from selenium import webdriver
from selenium.webdriver.support import ui, wait
from selenium.webdriver.support.wait import WebDriverWait

from common.connect_mysql import select_sql_all
from common.gol import post_printCode, dev_url, post_printDev, dev_url_2, dev_web_url, get_printDev
from common.gol import urlData_212, random_time, get_printCode
import allure, requests
from common.gol import mock_url

# def test_getAppendInfo():
#     '''用例描述：获取附加规则（渠道游戏个性化）,返回正确的结果'''
#     url = mock_url + '/config/getAppendInfo'
#     parm = {
#         'channelId': 'HW',
#         'gameId': 'cldpren5ld'
#     }
#     header = {
#         'X-Coding-Mock-Token': 'in82hqsvubfm6cmyrdoes44z2htlqqec'
#     }
#     r = requests.get(url, params=parm, headers=header)
#     get_printCode(requests.get(url, params=parm, headers=header))
#
# get_header = {
#         'X-Coding-Mock-Token': 'in82hqsvubfm6cmyrdoes44z2htlqqec'
#     }
# get_s = requests.Session()
# get_s.headers = get_header
# post_header = {
#     'X-Coding-Mock-Token': 'in82hqsvubfm6cmyrdoes44z2htlqqec',
#     'content-type': 'application/json'
# }
# post_s = requests.Session()
# post_s.headers = post_header
# test_yid = random_time()


# url = dev_url_2 + '/certification/info'
# print(url)
# header_value = {
#     'channel-id': 'AppStore',
#     'yid': '78684285',
#     'game-id': '1YA1teIrz',
#     'device-id': '26AF6DFF-8BCD-46F7-A947-0B66CE01DF8',
#     'game-version': '1.10',
#     'uid': 'asd'
# }
# # parm = {
# #     'uid': '123',
# #     'yid': '123'
# # }
# r = requests.get(url, headers=header_value)
# print(r.json())
#
#
# # import requests
# #
# # url = 'http://ais-frontend.cb64eaf4841914d918c93a30369d6bbc6.cn-beijing.alicontainer.com/ais/certification/info'
# #
# # payload = {}
# # headers = {
# #   'uid': 'asd',
# #   'yid': '79466319',
# #   'channel-id': 'AppStore',
# #   'game-id': '1YA1teIrz',
# #   'device-id': '26AF6DFF-8BCD-46F7-A947-0B66CE01DF8',
# #   'game-version': '1.10'
# # }
# #
# # response = requests.request('GET', url, headers=headers, data = payload)
# #
# # print(response.text.encode('utf8'))


# url = dev_url + "/white-list"
# body = {
#     "birthday": "1988-12-23",
#     "firstAttachmentUrl": "http://bj-ali-opp-portal-common-test.oss-cn-beijing.aliyuncs.com/%E6%B4%9B%E8%90%A8.jpg",
#     "id": 0,
#     "idCard": "130723198711111111",
#     "idCardType": "1",
#     "realName": "测试发出",
#     "secondAttachmentUrl": "http://bj-ali-opp-portal-common-test.oss-cn-beijing.aliyuncs.com/%E6%B4%9B%E8%90%A8.jpg",
#     "uid": "5f895190461df341a56d0f67"
# }
# post_printDev(requests.post(url, data=json.dumps(body)))
import selenium.webdriver.support.ui as ui
from selenium import webdriver
import time

# def OpenBrowser():
#     # browser=webdriver.Firefox(executable_path='C://Program Files/Mozilla Firefox/geckodriver')
#     browser = webdriver.Chrome()
#     browser.maximize_window()
#     browser.get("https://space-test.yodo1.com/admin-web/login")
#     print("当前使用的浏览器是：", browser.name)  # 打印当前使用的浏览器名称
#     print("当前网页title是：", browser.title)  # 打印页面title
#     time.sleep(1)
#     browser.find_element_by_id('tab-ldap').click()
#     browser.find_element_by_xpath("//input[@type='text']").click()
#     name1 = browser.find_element_by_xpath("//input[@type='text']")
#     name1.send_keys('zhoukangkang')
#     browser.find_element_by_xpath("//input[@type='password']").click()
#     pwd = browser.find_element_by_xpath("//input[@type='password']")
#     pwd.send_keys('Zkkzkk1988')
#     browser.find_element_by_css_selector('.el-button').click()
#     # return browser
# from common.connect_mysql import select_sql_all
#
# browser = webdriver.Chrome()
# browser.get("https://space-test.yodo1.com/admin-web/login")
# print("当前使用的浏览器是：", browser.name)  # 打印当前使用的浏览器名称
# print("当前网页title是：", browser.title)  # 打印页面title)
# time.sleep(1)
#
# wait = ui.WebDriverWait(browser, 5)
# wait.until(lambda browser: browser.find_element_by_xpath('//*[@id="app"]/div/div/div[2]/input').is_displayed())
# # # driver.find_element_by_xpath('//*[@id="app"]/div/div/div[2]/input')    #优化成until等待
# browser.find_element_by_xpath('//*[@id="app"]/div/div/div[2]/input').click()
# userName = browser.find_element_by_xpath('//*[@id="app"]/div/div/div[2]/input')
# userName.send_keys('yodo1@yodo1.com')
#
# browser.find_element_by_xpath('//*[@id="app"]/div/div/div[3]/span/input')
# browser.find_element_by_xpath('//*[@id="app"]/div/div/div[3]/span/input').click()
# password = browser.find_element_by_xpath('//*[@id="app"]/div/div/div[3]/span/input')
# password.send_keys('123456')
#
# browser.find_element_by_xpath('//*[@id="app"]/div/div/div[5]/button')
# browser.find_element_by_xpath('//*[@id="app"]/div/div/div[5]/button').click()
# time.sleep(1)
# userRealName = browser.find_element_by_xpath('//*[@id="app"]/section/section[2]/div[1]/header/div/div/a/span[2]')
# print("页面源码：", userRealName.text)
# userPackageCount = browser.find_element_by_xpath('//*[@id="app"]/section/section[2]/div[2]/main/div/div[1]/div[1]/div[2]/form/div[1]/div[2]/div')
# print("页面源码：", userPackageCount.text)
#
# test_dbinfo = {
#             "host": "rm-2zev9dj4ky5d09pf98o.mysql.rds.aliyuncs.com",
#             "user": "zhoukangkang",
#             "password": "L89EV8a$saRJ5b@",
#             "port": 3306
#         }
#
# sql = "select * from anti_developer_account a INNER JOIN anti_developer_package p on a.developer_id = p.developer_id where a.developer_id='2'"
# result = select_sql_all(sql, db_cof=test_dbinfo, dbname="space-web")
# print(result)
#
# time.sleep(3)
# browser.close()  # 关闭当前窗口
# browser.quit()  # 退出浏览器

# from time import sleep
#
# from playwright import sync_playwright
#
# # 注意：默认是无头模式
#
# with sync_playwright() as p:
#     # 分别对应三个浏览器驱动
#     for browser_type in [p.chromium, p.firefox, p.webkit]:
#         # 指定为有头模式，方便查看
#         browser = browser_type.launch(headless=False)
#         page = browser.newPage()
#         page.goto('http://baidu.com')
#
#         # 执行一次搜索操作
#         page.fill("input[name=\"wd\"]", "AirPython")
#         with page.expect_navigation():
#             page.press("input[name=\"wd\"]", "Enter")
#
#         # 等待页面加载完全
#         page.waitForSelector("text=百度热榜")
#
#         # 截图
#         page.screenshot(path=f'example-{browser_type.name}.png')
#
#         # 休眠5s
#         sleep(5)
#
#         # 关闭浏览器

#
# from selenium import webdriver
# browser = webdriver.Chrome()
# browser.get('http://www.baidu.com')

from functools import wraps

# def log(func):
#     def wrapper(*args, **kwargs):
#         result = func(*args)
#         print(func.__name__,'has been called')
#         return result
#     return wrapper
#
# @log
# def add(x, y):
#     result = x+y
#     return result
#
# if __name__ == '__main__':
#     print(add(1, 2))
#     print(add.__name__)
#
from collections import Counter

a = [2, 3, 34, 46, 42, 24, 38, 234, 475, 242, 32, 364, 23, 242, 464, 390]
print(Counter(a))  # 查看元素出现的次数
bb = a[-10:]
cc = a[::-1]
print(bb)
print(cc)
op = ["a", "bv", "dw"]
print(op[::-1])
a.sort(reverse=True)
print(sorted(a))
print(a)

# asss = (1, 5)
# qwe = asss[0]
# print(qwe)


# a = input("请输入a")
# b = input("请输入b")
# c = input("请输入c")
# if a == b or b ==c or a == c:
#     print("是个等腰三角形")
# else1
#
# def now():
#     """只要调用过一次，这个函数就是运行一次内部"""
#     print('你好我是now函数！')
# f = now
# f()
#
# print(f.__name__)
import time


def log(fun):
    def wrapper(*args, **kwargs):
        print("call %s():" % fun.__name__)
        return fun(*args, **kwargs)

    return wrapper


"""
*args:1、将参数打包给元组 2、将变量以外的剩余参数打包到元组里
**kwargs：1、将参数打包成字典 2、将参数以k:y形式打包成字典
args、*args、**kwargs顺序不能错
"""


@log
def now():
    print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))


now()


def make_adder(addend):
    def adder(augend):
        return augend + addend

    return adder


"""闭包：函数体内的函数里定义的变量时外函数的入参形参，.
在外部给函数定义时赋值不同参数，相同调用后得到的结果也不一样"""
p1 = make_adder(5)
b1 = make_adder(6)
print(p1(10))
print(b1(10))


def hellocounter(name):
    count = [0]

    def counter():
        count[0] += 1
        print('Hello,', name, ',', str(count[0]) + ' access!')

    return counter


hello = hellocounter('ma6174')
hello()
hello()
hello()


def makebold(fn):
    def wrapped():
        print("2<b>" + fn() + "</b>2")
        return "2<b>" + fn() + "</b2>"

    return wrapped


def makeitalic(fn):
    def wrapped():
        print("1<i>" + fn() + "</i>1")
        return "1<i>" + fn() + "</i>1"

    return wrapped


@makebold
@makeitalic
def hello():
    return "hello world"


sd = [22, 55, 67]
new_list = filter(lambda arg: arg > 23, sd)
print(new_list)
print(list(new_list))
# 拉姆达表达式主要是起到一个速写函数的作用，封装有限的逻辑
f = lambda x, y: x + y
print(f(1, 4))
[]


# 斐波那契数列
def fib(n):
    if n < 2:
        print("您输入的不满足条件大于0且小于2，请重新输入！", n)
        return n
    else:
        return fib(n - 1) + fib(n - 2)


print("斐波那契", fib(25))


# 最长子序列
def lis(arr):
    n = len(arr)
    m = [0] * n
    for x in range(n - 2, -1, -1):
        for y in range(n - 1, x, -1):
            if arr[x] < arr[y] and m[x] <= m[y]:
                m[x] += 1
        max_value = max(m)
        result = []
        for i in range(n):
            if m[i] == max_value:
                result.append(arr[i])
                max_value -= 1
    return result


arr = [10, 22, 9, 33, 21, 50, 41, 60, 80]
print(lis(arr))

# coding=utf-8
# class BinarySearch(object):
#     def binary_search(self, array, data):
#         """二分查找法递归实现"""
#         if len(array) == 0:
#             return False
#         array.sort()
#         mid_index = len(array) // 2
#         if array[mid_index] == data:
#             return True
#         return self.binary_search(array[mid_index + 1:], data) if data > array[mid_index] else \
#             self.binary_search(array[:mid_index], data)
#
# if __name__ == '__main__':
#     array = [50, 77, 55, 29, 10, 30, 66, 18, 80, 51]
#     search = BinarySearch()
#     print('搜索结果：', search.binary_search(array, 77))
#     print('搜索结果：', search.binary_search(array, 777))
#
#
# a = [1, 1, 2, 4, 5]
# a.insert(3, 8)
# print(a)

# a.append("r")   a.extend(list2)  a.insert(0, 5)  list3 = list1+ list2
# a.pop(3)返回删除的元素   a.remove(3)

import pytest


@pytest.mark.parametrize(('x', 'y'), [(1, 1), (1, 0), (0, 1)])
def test_simple(x, y):
    print("测试数据x:{},y:{}".format(x, y))
    assert x == y
    assert x + y > 1
    assert x > 0

# ly = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1]
# lll = []
#
#
# def digui(ly):
#     for i in ly:
#         if i % 3:
#             # lll.append(i)
#             print("本次取余不为0", i)
#         else:
#             print("本次取余为0", i)
#             ly.remove(i)
#             print("递归后的结果", ly)
#             digui(ly)
#
#
# print("依次取数判断是否取余不为0，存入新list中", lll)
# digui(ly)
# print(ly)

@pytest.mark.parametrize(('x', 'y'), [(1, 1), (1, 0), (0, 1)])
def test_simple(x, y):
    print("测试数据x:{},y:{}".format(x, y))
    assert x == y, "两个数不相等"
    assert x + y > 1, "x+y不大于1"
    assert x > 0, "x不大于0"